﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace MEF_Test.Contracts
{
    
        public class ParameterlessCommand : ICommand
        {
            public ParameterlessCommand(Action executeMethod, Func<bool> canExecuteMethod)
            {
                _executeMethod = executeMethod;
                _canExecuteMethod = canExecuteMethod;
            }
            private Action _executeMethod;
            private Func<bool> _canExecuteMethod;
            #region ICommand Members
            /// <summary>
            /// Invokes the delegate passed as an argument to the constructor for CanExecute
            /// </summary>
            /// <param name="parameter"></param>
            /// <returns></returns>
            public bool CanExecute(object parameter)
            {
                return _canExecuteMethod();
            }
            /// <summary>
            /// Invokes the delegate passed as an argument to the constructor for Execute
            /// </summary>
            /// <param name="parameter"></param>
            public void Execute(object parameter)
            {
                _executeMethod();
            }

            // This is necessary tu notify the CommandManager he's in charge of a new ICommand.
            // This is necessary for advanced features such as forcing the reevaluation of the CanExecute method !
            public event EventHandler CanExecuteChanged
            {
                add { CommandManager.RequerySuggested += value; }
                remove { CommandManager.RequerySuggested -= value; }
            }

        

            #endregion
        }
    
}
